package com.mentaleye.controller;

import com.baidu.ueditor.ActionEnter;
import com.mentaleye.bean.StudentActivityBean;
import com.mentaleye.biz.StudentActivityBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Controller
@RequestMapping("/edit")
public class FileUpload {
	@Autowired
	private StudentActivityBiz studentActivityBiz;
	/*@RequestMapping("/add")
	public ModelAndView addEdit(){
		ModelAndView view = new ModelAndView("em/fileUpload/addPhoto");
		return view;
	}*/

	@RequestMapping(value = "/add")
	public ModelAndView add(@RequestParam(value = "activityId", required = false) Integer activityId) {
		ModelAndView view = new ModelAndView("em/fileUpload/addPhotos");
		view.addObject("activityId", activityId);
		StudentActivityBean bean = studentActivityBiz.getActivityById(activityId);
		view.addObject("studentActivity", bean);
		return view;
	}

	@RequestMapping(value = "/config")
	public void config(HttpServletRequest request,HttpServletResponse response) {
		try {
			response.setContentType("application/json");
			request.setCharacterEncoding( "utf-8" );
			response.setHeader("Content-Type" , "text/html");
			//String rootPath = application.getRealPath( "/" );
			String rootPath=request.getSession().getServletContext().getRealPath("/");

			String exec=new ActionEnter(request,rootPath).exec();
			PrintWriter writer=response.getWriter();
			writer.write(exec);
			writer.flush();
			writer.close();
		}catch (Exception e){
			e.printStackTrace();
		}

	}
}
